//
//  NotificationCenter+Helper.swift
//  Scanread
//
//  Created by Macintosh on 2023/6/20.
//

import Foundation

public enum NotificationName: String {
    // 改变window root
    case windowRootChanged
    case adShowed
    case adInitSuccessed
    case authChanged
    // 微信登录
    case weChatLoginResponse
    case networkStatusChanged
}

public extension  NotificationName {
    var value: String {
        return "SR" + rawValue
    }

    var name: Notification.Name {
        return Notification.Name(value)
    }
}


public extension NotificationCenter {
    func post(_ forName: NotificationName, object: Any? = nil, userInfo: [AnyHashable: Any]? = nil) {
        post(name: forName.name, object: object, userInfo: userInfo)
    }

    func addObserver(forName name: NotificationName, object obj: Any? = nil, queue: OperationQueue? = OperationQueue.current, using block: @escaping (Notification) -> Void) {
        addObserver(forName: name.name, object: obj, queue: queue, using: block)
    }
    
    func removeObserver(_ observer: Any, name aName: NotificationName, object anObject: Any?) {
        removeObserver(observer, name: aName.name, object: anObject)
    }
}

